const logger = require('../helper/logger')

const tableName = 'wallet_address'

module.exports = async (db) => {
  try {
    const exists = await db.schema.hasTable(tableName)
    if (!exists) {
      await db.schema.createTable(tableName, (table) => {
        table.charset('utf8')
        table.increments('id')
        table.string('currency').notNullable()
        table.string('address').notNullable()
        table.boolean('enabled').defaultTo(true).notNullable()
        table.timestamps(false, true)
      })
      logger.info(`Created ${tableName} table`)
      const items = [
        {
          currency: 'BTC',
          address: '33fz6pAzNiQWvzvMRvMheM4642ahHpErcS',
        },
        {
          currency: 'ETH',
          address: '0xadbd0e1a569ce5ae35951540a4fec34c4ba14f44',
        },
      ]
      await db.batchInsert(tableName, items).then()
    }
  } catch (error) {
    logger.error(`Error creating ${tableName} table`, error)
  }
}
